package com.quan.sdk.weixin.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.quan.common.properties.WeixinConfigProperties;
import com.quan.sdk.weixin.scheduler.AccessTokenRefreshTask;
import com.quan.sdk.weixin.scheduler.JsApiTicketRefreshTask;
import com.quan.sdk.weixin.utils.WeixinContext;

@Order(value = 1)
@Component
public class WeinxinInitRunner implements ApplicationRunner {
	
	@Autowired
	private WeixinConfigProperties weixinConfigProperties;
	
	@Autowired
	private AccessTokenRefreshTask accessTokenRefreshTask;
	
	@Autowired
	private JsApiTicketRefreshTask apiTicketRefreshTask;

	/**
	 * 程序启动执行，初始化微信配置信息
	 */
	@Override
	public void run(ApplicationArguments args) throws Exception {
		WeixinContext.setAppId(this.weixinConfigProperties.getAppId());
		WeixinContext.setAppSecret(this.weixinConfigProperties.getAppSecret());
		WeixinContext.setToken(this.weixinConfigProperties.getToken());
		
		this.accessTokenRefreshTask.accessTokenRefreshJob();
		this.apiTicketRefreshTask.accessJsApiTicketRefreshJob();
	}

}
